home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / n_b_v203.zip / 32BITPTR.DMO < prev    next >
Text File  |  1996-07-04  |  5KB  |  80 lines

  1. $if 0
  2.     ┌──────────────────────────╖                        PowerBASIC v3.20
  3.  ┌──┤          DASoft          ╟──────────────────────┬──────────────────╖
  4.  │  ├──────────────────────────╢    Copyright 1995    │ DATE: 1995-10-01 ╟─╖
  5.  │  │ FILE NAME   32BITPTR.DMO ║          by          ╘════════════════─ ║ ║
  6.  │  │                          ║  Don Schullian, Jr.                     ║ ║
  7.  │  ╘══════════════════════════╝                                         ║ ║
  8.  │ A license is hereby granted to the holder to use this source code in  ║ ║
  9.  │ any program, commercial or otherwise,  without receiving the express  ║ ║
  10.  │ permission of the copyright holder and without paying any royalties,  ║ ║
  11.  │ as long as this code is not distributed in any compilable format.     ║ ║
  12.  │  IE: source code files, PowerBASIC Unit files, and printed listings   ║ ║
  13.  ╘═╤═════════════════════════════════════════════════════════════════════╝ ║
  14.    │                ....................................                   ║
  15.    ╘═══════════════════════════════════════════════════════════════════════╝
  16.  
  17. Many of the SUBs and FUNCTIONs in this library work with scaler arrays. Data
  18. may be moved, counted, or, in some way, reworked. Most of them have a cousin
  19. for strings, flex strings, types, etc. but there are times when it is easier
  20. to work with 32bit pointers and as pointers simply point to data and have no
  21. real relationship with their data type you can do some pretty neat stuff BUT
  22. you are in charge and if you blow it you can do a real tap dance on the data
  23. in memory.
  24.  
  25. For our purposes here I will work with the QCopyXXX family of routines. This
  26. set has all the above mentioned members and will show just exactly what kind
  27. of tricks can be pulled when you use pointers.
  28.  
  29. QCopyARR used to have 3 alias' QCopyARR2PTR, QCopyPTR2ARR, and QCopyPTR2PTR.
  30. They were all the same .ASM routine but to get PowerBASIC to work with our
  31. version of 32bit pointers we had to declare each of them differently:
  32.  
  33.     DECLARE SUB QCopyARR2PTR (SEG ANY,   BYVAL T???,BYVAL Bytes%)
  34.     DECLARE SUB QCopyPTR2ARR (BYVAL F???,SEG ANY,   BYVAL Bytes%)
  35.     DECLARE SUB QCopyPTR2PTR (BYVAL F???,BYVAL T???,BYVAL Bytes%)
  36.  
  37. Notice the similarity in how PowerBASIC now accepts pointers? This is no
  38. coincidence as when you pass a scaler variable by SEG you are, in fact,
  39. only pushing the 32bit pointer onto the stack so memory can be directly
  40. addressed, read and/or changed. <<<BUT>>> when you pass any of the strings
  41. by SEG you are passing only the string handle and NOT the pointer so be
  42. careful that you use this little pointer trick in place of scaler arrays
  43. and not strings!
  44.  
  45. $endif
  46.  
  47. OPTION BASE 0
  48.                                              '┌──────────────────────────────
  49. $INCLUDE "DAS-NB01.INC"                      '│ None of the uses for QCopyXXX
  50. COLOR 7, 0                                   '│ below are "normal". They have
  51. CLS                                          '│ all been tricked into doing
  52.                                              '│ work they were not designed
  53. DIM A?(10)                                   '│ to do by passing pointers
  54. S$ = SPACE$(11)                              '│
  55. D$ = "HELLO WORLD"                           '│
  56.                                              '│
  57. Aptr??? = VARPTR32( A?(0) )                  '│ 32bit pointers to the 3 vars
  58. Sptr??? = STRPTR32( S$ )                     '│ note we are using only the
  59. Dptr??? = STRPTR32( D$ )                     '│ values and don't have to
  60.                                              '│ declare the vars as PTRs
  61.                                              '│
  62. QCopyARR BYVAL Dptr???, BYVAL Sptr???, 11    '│ this should be array to array
  63. PRINT "S$ NOW EQUALS: "; S$                  '│ but we are copying string to
  64. PRINT                                        '│ string
  65.                                              '│
  66. QCopyARR BYVAL Dptr???, BYVAL Aptr???, 11    '│ now we are going from string
  67. PRINT "AND HERE ARE THE ASCII VALUES"        '│ to array
  68. FOR X% = 0 TO 10                             '│
  69.   PRINT USING "##_, "; A?(X%);               '│
  70. NEXT                                         '│
  71. PRINT : PRINT                                '│
  72.                                              '│
  73. N$ = fQcopy$( BYVAL Aptr???, 11 )            '│ from an array into a string
  74. PRINT "fCopy$ makes a copy of memory: "; N$  '│
  75. PRINT                                        '│
  76.                                              '│
  77. Z$ = "XXXXXXXXXXX"                           '│ and, finally from a string
  78. QCopySTR Z$, BYVAL Sptr???                   '│ back into a string
  79. PRINT S$                                     '│
  80.                                              '└──────────────────────────────